/**
 *
 * Created by Song,Yewen, 9/9/2011 2:02:03 PM
 *
 */

function  validateVideoUrl(ori_url) 
{
    //We use a fake constant duration for gametrailers.com, because it is Game trailer, not long duration video
    //TODO: FIXME
    var fcduration = '100'; 
	var html = download_page(ori_url);
	var result_url = copyBetween(html, '<span class="Downloads">', '</span>');
	if (result_url == null) {
		// Not Found
	  	return 'NotFoundVideo';
	}
	result_url = copyBetween(result_url, 'href="', '"');
	if (result_url == null) {
		// Not Found
	  	return 'NotFoundVideo';
	}	
	
	//var matches = html.match(/<title>(.*?)<\/title>/);
	var matches = html.match(/<title>([\s\S]*?)<\/title>/);
    if(matches){
 	   return 'success_title:' + encodeURIComponent(matches[1])
 	          + '\n video_urls:' + encodeURIComponent(flv_string)
 	          + '\n seconds:' + Math.round(parseInt(fcduration));
    }
    return 'error:empty_path';
}

/* http://www.gametrailers.com/video/debut-ps3-xbox-crysis/720428 */
function js_get_media_url(ori_url) 
{
	var html = download_page(ori_url);
	var result_url = copyBetween(html, '<span class="Downloads">', '</span>');
	if (result_url == null) {
		// url not found
		return '';
	}
	result_url = copyBetween(result_url, 'href="', '"');
	if (result_url == null)
		return '';
	var flv_string = 'http://www.gametrailers.com' + result_url;

	return flv_string;
}
